<?php 
//comment to user.
// this pager is supposed to be used along with the javascript that appears on the public library
// page. You  bind to each link and perform an ajax call to retrieve the associated page, this is
//why there are only numbers in the hrefs

?>




<div class="pager">


<?php if(($page != $pages) && $pages > 1):?>
		<p class="next"><a href="<?php echo($page+1)?>">Next 5 Resources &raquo;</a></p>

<?php endif?>
<?php if($page != 1):?>

		<p class="prev"><a href="<?php echo ($page-1)?>">&laquo; Previous 5 Resources</a></p>

<?php endif?>



<?php 
//the following code create the navigation bar for the pages it currently creates the format
// 1 2 3 4 .... [last page] or 1....5 6 7 8 9 10 11 12... [last page] or 1... 12 13 [last page]
// currently these formats are chosen by the fact that I want to always have 8 middle choices showing
// this means that the elippses will start showing at 12 pages so at 11 pages you get 
// 1 2 3 4 5 6 7 8 9 10 11 
?>

<ul>

<?php if($pages >= 12):?>

	<?php if($page >= 6):?>
	
		<li><a href="1">1</a></li>
		<li> ... </li>
		
		<?php for($i=$page-3;$i<$page; $i++):?>
			<li><a href="<?php echo $i?>"><?php echo$i?></a></li>
		<?php endfor ?>
		
		<li class="current"><a href="<?php echo $page?>"><?php echo $page?></a></li>
		
		<?php if($page+4 >= $pages-1):?>
		
			<?php for($i=$page+1;$i<=$pages; $i++):?>
				<li><a href="<?php echo $i?>"><?php echo$i?></a></li>
			<?php endfor ?>
			
		<?php else:?>
			
			<?php for($i=$page+1;$i<=$page+4; $i++):?>
				<li><a href="<?php echo $i?>"><?php echo $i?></a></li>
			<?php endfor ?>
				<li> ... </li>
				<li><a href="<?php echo $pages?>"><?php echo $pages?></a></li>			
		<?php endif ?>
			
	<?php else:?>
	
			<?php for($i=1;$i<=$page+4; $i++):?>
				<?php if($i == $page):?>
					<li class="current"><a href="<?php echo $i?>"><?php echo$i?></a></li>
				<?php else:?>
					<li><a href="<?php echo $i?>"><?php echo$i?></a></li>
				<?php endif?>
			<?php endfor ?>
				<li> ... </li>
				<li><a href="<?php echo $pages?>"><?php echo$pages?></a></li>
	<?php endif?>
	
<?php else:?>

	<?php for($i=1;$i<=$pages; $i++):?>
		<?php if($i == $page):?>
			<li class="current"><a href="<?php echo $i?>"><?php echo$i?></a></li>
		<?php else:?>
			<li><a href="<?php echo $i?>"><?php echo$i?></a></li>
		<?php endif?>
	<?php endfor ?>

<?php endif?>
</ul>
		
</div>
		